package yxy.game.pm2.command.plainsCraft;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsCraftMessage;
import yxy.game.pm2.module.plainsCraft.PlainsCraftHandle;

/** 中原争霸 中原争霸晋级挑战 */
@MessageType(proto = Command.PlainsCraftChanllengePromoted, classtype = PlainsCraftMessage.PlainsCraftChanllengePromotedRequest.class)
public class CMD_PlainsCraftChanllengePromoted extends Command<PlainsCraftMessage.PlainsCraftChanllengePromotedRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsCraftMessage.PlainsCraftChanllengePromotedRequest request) {
		String playerCode = messageSource.getTag();

		PlainsCraftMessage.PlainsCraftChanllengePromotedResponse.Builder response = PlainsCraftMessage.PlainsCraftChanllengePromotedResponse.newBuilder();

		Result result = new PlainsCraftHandle().battleResponsePromoted(playerCode, request.getRank(), response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, PlainsCraftMessage.PlainsCraftChanllengePromotedResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}